<?php

/*
 * @author Ebrain Cedeno <ebraincedeno@gmail.com>
 */

class VeCms{
    
    
    public static function getPathRoot(){
        
        extract($_SERVER);
        $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI);
        if (file_exists($url_path)){
            return $url_path;
        }
        else{
            throw new Exception("no se encontro el directorio raiz");
        }
        
    }
    
    public static function getPathCss(){
        
        extract($_SERVER);
        
        $modules = substr(str_replace($SCRIPT_NAME,"",$PHP_SELF),1);
        if ($modules != ""){
            $url_param = explode("/",substr(str_replace($SCRIPT_NAME,"",$PHP_SELF),1));
            $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI)."base/css";
            $url_path = str_replace(implode($url_param,"/"),"", $url_path);
            
        }
        else{
            $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI)."base/css";
        }
        
        return $url_path;   
    }
    
    public static function getPathJs(){
        extract($_SERVER);
        
        $modules = substr(str_replace($SCRIPT_NAME,"",$PHP_SELF),1);
        
        if ($modules != ""){
            $url_param = explode("/",substr(str_replace($SCRIPT_NAME,"",$PHP_SELF),1));
            $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI)."base/javascript";
            $url_path = str_replace(implode($url_param,"/"),"", $url_path);
            
        }
        else{
            $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI)."base/javascript";
        }
        
        return $url_path;
    }
    
    public static function getPathImage(){
        extract($_SERVER);
        
        $modules = substr(str_replace($SCRIPT_NAME,"",$PHP_SELF),1);
        if ($modules != ""){
            $url_param = explode("/",substr(str_replace($SCRIPT_NAME,"",$PHP_SELF),1));
            $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI)."base/image";
            $url_path = str_replace(implode($url_param,"/"),"", $url_path);
            
        }
        else{
            $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI)."base/image";
        }
        
        return $url_path;
    }
    
    public static function getPathTemplete(){
        extract($_SERVER);
        $modules = substr(str_replace($SCRIPT_NAME,"",$PHP_SELF),1);
        if ($modules != ""){
            $url_param = explode("/",substr(str_replace($SCRIPT_NAME,"",$PHP_SELF),1));
            $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI)."theme";
            $url_path = str_replace(implode($url_param,"/"),"", $url_path);
            
        }
        else{
            $url_path = "http://".$HTTP_HOST.str_replace(basename($SCRIPT_NAME),"",$REQUEST_URI)."theme";
        }
        
        return $url_path;
        
    }
    
    public static function loadJsBase(){
        return '<script type="text/javascript" src="'.self::getPathJs().DIRECTORY_SEPARATOR.'jquery-1.8.3.js"></script>';
    }
    
    public static function createUrl($url,$param=array(),$optionsHtml=array()){
    global $configure;    
        extract($_SERVER);
        if (count($param) > 0){
            
            $getParameter = '?';
            foreach($param as $llave=>$value){
                $getParameter .= $llave."=".$value."&";
            }
        
            $getParameter = substr($getParameter, 0,-1);
        }
        else{
            $getParameter = "";
        }
        
        extract($_SERVER);
        if (stripos(strtolower($REQUEST_URI),"index.php")=== false){
            $url = str_replace("./","",$url);
            $modulo = array_keys($configure['module_default']);
            $url = 'index.php/'.$modulo[0]."/".$url;
        }
        
        return $url.$getParameter;
    }
    
}

class VeCmsEnum{
    CONST MODULE =0;
    CONST ACTION =1;
}

?>
